package org.celery.modules.merchant.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.celery.modules.merchant.entity.MerchantDeskCategory;
import org.celery.modules.merchant.vo.MerchantDeskCategoryVO;
import org.celery.modules.merchant.wrapper.MerchantDeskCategoryWrapper;
import org.celery.modules.merchant.service.IMerchantDeskCategoryService;
import org.springblade.core.boot.ctrl.BladeController;

import java.util.List;

/**
 * 商户桌台类别表. 控制器
 *
 * @author Celery
 * @since 2021-11-07
 */
@RestController
@AllArgsConstructor
@RequestMapping("celery-merchant/merchant-desk-category")
@Api(value = "商户桌台类别表.", tags = "商户桌台类别表.接口")
public class MerchantDeskCategoryController extends BladeController {

	private final IMerchantDeskCategoryService merchantDeskCategoryService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入merchantDeskCategory")
	public R<MerchantDeskCategoryVO> detail(MerchantDeskCategory merchantDeskCategory) {
		MerchantDeskCategory detail = merchantDeskCategoryService.getOne(Condition.getQueryWrapper(merchantDeskCategory));
		return R.data(MerchantDeskCategoryWrapper.build().entityVO(detail));
	}

	/**
	 * 分页 商户桌台类别表.
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入merchantDeskCategory")
	public R<IPage<MerchantDeskCategoryVO>> list(MerchantDeskCategory merchantDeskCategory, Query query) {
		QueryWrapper<MerchantDeskCategory> queryWrapper = Condition.getQueryWrapper(merchantDeskCategory);
		queryWrapper.lambda().orderByAsc(MerchantDeskCategory::getSort);
		IPage<MerchantDeskCategory> pages = merchantDeskCategoryService.page(Condition.getPage(query), queryWrapper);
		return R.data(MerchantDeskCategoryWrapper.build().pageVO(pages));
	}


	/**
	 * 自定义分页 商户桌台类别表.
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入merchantDeskCategory")
	public R<IPage<MerchantDeskCategoryVO>> page(MerchantDeskCategoryVO merchantDeskCategory, Query query) {
		IPage<MerchantDeskCategoryVO> pages = merchantDeskCategoryService.selectMerchantDeskCategoryPage(Condition.getPage(query), merchantDeskCategory);
		return R.data(pages);
	}

	/**
	 * 新增 商户桌台类别表.
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入merchantDeskCategory")
	public R save(@Valid @RequestBody MerchantDeskCategory merchantDeskCategory) {
		return R.status(merchantDeskCategoryService.save(merchantDeskCategory));
	}

	/**
	 * 修改 商户桌台类别表.
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入merchantDeskCategory")
	public R update(@Valid @RequestBody MerchantDeskCategory merchantDeskCategory) {
		return R.status(merchantDeskCategoryService.updateById(merchantDeskCategory));
	}

	/**
	 * 新增或修改 商户桌台类别表.
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入merchantDeskCategory")
	public R submit(@Valid @RequestBody MerchantDeskCategory merchantDeskCategory) {
		return R.status(merchantDeskCategoryService.saveOrUpdate(merchantDeskCategory));
	}

	
	/**
	 * 删除 商户桌台类别表.
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(merchantDeskCategoryService.deleteLogic(Func.toLongList(ids)));
	}

	/**
	 * 选项列表 商户桌台类别表.
	 */
	@GetMapping("/select")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "选项列表", notes = "传入merchantDeskCategory")
	public R<List<MerchantDeskCategory>> select(MerchantDeskCategory merchantDeskCategory) {
		QueryWrapper<MerchantDeskCategory> queryWrapper = Condition.getQueryWrapper(merchantDeskCategory);
		queryWrapper.lambda().orderByAsc(MerchantDeskCategory::getSort);
		return R.data(merchantDeskCategoryService.list(queryWrapper));
	}
	
}
